package org.cgc.gui;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class InfoWindow extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String infoString;

	
	public InfoWindow(String htmlFile) {
		setTitle("Info");
		initInfoString(htmlFile);
		initView();
		setSize(800, 600);
		setVisible(true);
	}
	
	private void initView() {
		JLabel info = new JLabel(infoString);
		JScrollPane pane = new JScrollPane(info);
		add(pane);
	}
	
	private void initInfoString(String htmlFile) {
		
		BufferedReader stream = null;
		String text = "";
		String line = null;
		
		try {
			stream = new BufferedReader(new FileReader(htmlFile));
			
			if (!stream.ready()) throw new IOException();
			
			while((line = stream.readLine()) != null) {
				text += line;
			}
			
			infoString = text;
		}
		catch(FileNotFoundException ex) {
			infoString = "Error: Source file not found.";
		}
		catch(Exception ex) {
			throw new RuntimeException();
		}
		finally {
			try {
				if(stream != null)
					stream.close();
			}
			catch (IOException ex) {
				throw new RuntimeException();
			}
		}
	}
}
